﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace RouletteD5
{
    public static class RouletteExtension
    {
        /// <summary>
        /// compare two image
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <returns>true if match else false</returns>
        public static bool EqualTo(this Image source, Image target)
        {
            if (source.Size != target.Size) return false;

            var src = new System.IO.MemoryStream();
            source.Save(src, System.Drawing.Imaging.ImageFormat.Jpeg);

            var tg = new System.IO.MemoryStream();
            target.Save(tg, System.Drawing.Imaging.ImageFormat.Jpeg);

            string firstImage = Convert.ToBase64String(src.ToArray());
            string secondImage = Convert.ToBase64String(tg.ToArray());

            src = null;
            tg = null;

            return firstImage.Equals(secondImage);
        }

        /// <summary>
        /// compare two image
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <returns>true if match else false</returns>
        public static int DiffPosition(this Image source, Image target)
        {
            if (source.Size != target.Size) return -1;

            var src = new System.IO.MemoryStream();
            source.Save(src, System.Drawing.Imaging.ImageFormat.Jpeg);

            var tg = new System.IO.MemoryStream();
            target.Save(tg, System.Drawing.Imaging.ImageFormat.Jpeg);

            string firstImage = Convert.ToBase64String(src.ToArray());
            string secondImage = Convert.ToBase64String(tg.ToArray());

            src = null;
            tg = null;

            return string.Compare(firstImage, secondImage);
        }
    }
}
